<?php
class ModelModuleBossBoughtTogether extends Model {
	public function getProductBoughtTogether($product_id) {
		$product_data = array();
        
        $sql = $this->db->query("SELECT COUNT(*) as total FROM information_schema.tables WHERE table_schema = '".DB_DATABASE."' AND table_name = '" . DB_PREFIX . "product_bought_together'");
        
        if($sql->row['total']==1){
    		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_bought_together pbt LEFT JOIN " . DB_PREFIX . "product p ON (pbt.bought_together_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pbt.product_id = '" . (int)$product_id . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'");
    	
        	$this->load->model('catalog/product');
    	
        	foreach ($query->rows as $result) { 
    			$product_data[$result['bought_together_id']] = $this->model_catalog_product->getProduct($result['bought_together_id']);
    		}
    		
    		return $product_data;
      } else{
            return NULL;
        }
	}
}
?>